<?php
namespace app\index\controller;

use app\common\model\PieceShare;
use think\Controller;

class BaseController extends Controller
{
    protected $user_info;
    public function __construct()
    {
        parent::__construct();
        $this->checkAuth();
        $this->checkShare();

    }
    public function checkAuth(){
        //模拟已经登录
//        session('user_info',['id'=>1,'nickname'=>'德魔','openid'=>'sdfdsfdsfdsfdsfsdf']);
//        $this->user_info = session('user_info');
        //检查是否已经登录，没有登录要求跳转微信授权
        //检查参数
        if(empty(session('user_info'))){
            (new Auth())->getCode();
        }
        $this->user_info = session('user_info');
    }
    public function checkShare(){
        $is_share = 0;
        $share_data = null;
            if($share_id = input('share_id')){
            //有分享
            $share_data = PieceShare::getById($share_id);
            $share_data = $share_data->toArray();
            $is_share = 1;
            //执行领取操作
        }
        $this->assign('is_share',$is_share);
        $this->assign('share_id',$is_share?$share_data['id']:0);
        $this->assign('share_data',$is_share?$share_data:[]);
    }
}
